{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "CompletedProcess(args=['pip', 'install', 'pandas'], returncode=0)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import subprocess\n",
    "\n",
    "# 下载并安装pandas\n",
    "subprocess.run(['pip', 'install', 'pandas'])\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "生成一段代码，将指定页面http://10.48.2.250/result.html的内容保存为本地excel"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "import pandas as pd\n",
    "\n",
    "# 发送GET请求获取网页内容\n",
    "url = \"http://10.48.2.250/result.html\"\n",
    "response = requests.get(url)\n",
    "html_content = response.text\n",
    "\n",
    "# 使用BeautifulSoup解析网页内容\n",
    "from bs4 import BeautifulSoup\n",
    "soup = BeautifulSoup(html_content, 'html.parser')\n",
    "\n",
    "# 找到表格元素\n",
    "table = soup.find('table')\n",
    "\n",
    "# 提取表格数据\n",
    "data = []\n",
    "for row in table.find_all('tr'):\n",
    "    row_data = []\n",
    "    for cell in row.find_all('td'):\n",
    "        row_data.append(cell.text)\n",
    "    data.append(row_data)\n",
    "\n",
    "# 将数据保存为Excel文件\n",
    "df = pd.DataFrame(data)\n",
    "df.to_excel('result.xlsx', index=False)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.9"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
